package com.lcg.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lcg.demo.model.Items;
import com.lcg.demo.service.ItemsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api("HotelController相关api")
@RestController
@RequestMapping("/Item")
public class ItemsApi {

    private static final Logger logger = LoggerFactory.getLogger(ItemsApi.class);
	@Autowired
	private ItemsService itemsService;

	@ApiOperation(value = "根据Item的ID查询Items信息")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(paramType = "query", name = "Id", dataType = "int", value = "Item号", required = true) })
	@GetMapping("/item")
	public Items findItems(@RequestParam("Id") Integer Id) {
		logger.info("根据Item的ID查询Items信息,id号为：{}",Id);
		return itemsService.findItems(Id);

	}
	
	@ApiOperation(value = "根据Item的ID删除Items信息")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(paramType = "query", name = "Id", dataType = "int", value = "Item号", required = true) })
	@GetMapping("/deleteItem")
	public String deleteItems(@RequestParam("Id") Integer Id) {
		
		
		if(itemsService.deleteItems(Id)==1) {
			logger.info("根据Item的ID删除Items信息成功,id号为：{}",Id);
			return "sucess";
		}else {
			logger.debug("根据Item的ID删除Items信息失败,id号为：{}",Id);
			return "fail";
		}
		
		
	}
	
	  @ApiOperation(value = "新增Item")
	    @ApiImplicitParams(value = {
	            @ApiImplicitParam(paramType = "body", name = "items", dataType = "Items", value = "新增item", required = true)
	    })
	  @PostMapping("/insertItems")
	public String insertItems(@RequestBody Items items) {
		
		if(itemsService.insertItems(items)==1) {
			logger.info("新增Items信息成功,id号为：{}",items.getId());
			return "sucess";
		}else {
			logger.info("新增Items信息失败,id号为：{}",items.getId());
			return "fail";
		}
		
		 
	}
	

 

}
